package vn.edu.hcmut.cse.ai.search.problems.waterjug;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 *
 * @author ngphi
 */
public class ReadInput {

    private int sizeJug1;
    private int sizeJug2;
    private int startJug1;
    private int startJug2;
    private int goalJug1;
    private int goalJug2;

    public void handle(String filename) {
        List<String> rowString = new ArrayList<>();

        Path path = Paths.get(filename);
        try {
            rowString = Files.readAllLines(path, StandardCharsets.UTF_8);
        } catch (IOException e) {
            System.err.println("Error File");
        }
        int[][] array = new int[3][2];
        for (int i = 0; i < rowString.size(); i++) {
            String str = rowString.get(i);
            str = str.replaceAll("[^0-9]+", " ");
            List arr = Arrays.asList(str.trim().split(" "));
            for (int j = 0; j < arr.size(); j++) {
                array[i][j] = Integer.valueOf(arr.get(j).toString());
            }
        }
        this.sizeJug1 = array[0][0];
        this.sizeJug2 = array[0][1];
        this.startJug1 = array[1][0];
        this.startJug2 = array[1][1];
        this.goalJug1 = array[2][0];
        this.goalJug2 = array[2][1];
    }

    public int getStartJug1() {
        return startJug1;
    }

    public int getStartJug2() {
        return startJug2;
    }

    public int getGoalJug1() {
        return goalJug1;
    }

    public int getGoalJug2() {
        return goalJug2;
    }

    public int getSizeJug1() {
        return sizeJug1;
    }

    public int getSizeJug2() {
        return sizeJug2;
    }
}
